import { requestHos, requestPro } from "@/utils/http";
import { type } from "os";

//1.地区的每一项值的类型
export interface provinceItemType {
  id: number;
  createTime: string;
  updateTime: string;
  isDeleted: number;
  param: object;
  parentId: number;
  name: string;
  value: string;
  dictCode: null;
  hasChildren: boolean;
}
//3. 请求医院列表params参数类型
export interface hosListParamsType {
  page: number;
  limit: number;
  hoscode?: string;
  hosname?: string;
  hostype?: string;
  provinceCode?: string;
  cityCode?: string;
  districtCode?: string;
  status?: number;
}
//医院列表返回数据中bookingRule数据类型

export interface hosDataBookingRuleType {
  cycle: number;
  releaseTime: string;
  stopTime: string;
  quitDay: number;
  quitTime: string;
  rule: string[];
}

// 医院列表数据返回值中param的类型
export interface hosDataParamType {
  hostypeString: string;
  fullAddress: string;
}
//医院列表中每一项的类型
export interface hosDataListItemType {
  id: string;
  createTime: string;
  updateTime: string;
  isDeleted: number;
  param: hosDataParamType;
  hoscode: string;
  hosname: string;
  hostype: string;
  provinceCode: string;
  cityCode: string;
  districtCode: string;
  address: string;
  logoData: string;
  intro: string;
  route: string;
  status: number;
  bookingRule: hosDataBookingRuleType;
}

export type hosDataListType = hosDataListItemType[];

export interface HosListDataType {
  //不常用的类型直接写

  content: hosDataListType;
  pageable: {
    sort: {
      sorted: boolean;
      unsorted: boolean;
      empty: boolean;
    };
    pageNumber: number;
    pageSize: number;
    offset: number;
    paged: boolean;
    unpaged: boolean;
  };
  last: boolean;
  //总页数
  totalPages: number;
  //数据总条数
  totalElements: number;
  first: boolean;
  sort: {
    sorted: boolean;
    unsorted: boolean;
    empty: boolean;
  };
  numberOfElements: number;
  size: number;
  number: number;
  empty: boolean;
}

//医院详情返回值类型

export interface HosDetailType {
  bookingRule: hosDataBookingRuleType;
  hospital: {
    id: string;
    createTime: string;
    updateTime: string;
    isDeleted: number;
    param: hosDataParamType;
    hoscode: string;
    hosname: string;
    hostype: string;
    provinceCode: string;
    cityCode: string;
    districtCode: string;
    address: string;
    logoData: string;
    intro: null;
    route: string;
    status: number;
    bookingRule: null;
  };
}

//2. 地区的列表类型
export type provinceListType = provinceItemType[];
//医院科室每一项的类型
export interface hosScheduleItemType {
  depcode: string;
  depname: string;
  children: hosScheduleListType | null; //嵌套类型
}
//医院列表类型
export type hosScheduleListType = hosScheduleItemType[];

//医院排班日期表每一项类型
export interface hosScheduleDateItemType {
  workDate: string;
  workDateMd: null;
  dayOfWeek: string;
  docCount: number;
  reservedNumber: number;
  availableNumber: number;
  status: null;
}
//医院排班日期表类型
export type hosScheduleDateListType = hosScheduleDateItemType[];

//医院排班时间表返回值类型
export interface hosScheduleDateType {
  total: number;
  bookingScheduleList: hosScheduleDateListType;
  baseMap: {
    hosname: string;
  };
}

//单个医生排班列表类型
export interface scheduleItemType {
  id: string;
  createTime: string;
  updateTime: string;
  isDeleted: number;
  param: {
    dayOfWeek: string;
    depname: string;
    hosname: string;
  };
  hoscode: string;
  depcode: string;
  title: string;
  docname: string;
  skill: string;
  workDate: string;
  workTime: number;
  reservedNumber: number;
  availableNumber: number;
  amount: number;
  status: number;
  hosScheduleId: string;
}
//医生列表类型
export type scheduleListType = scheduleItemType[];

//请求方法1:请求省份
export const reqProvince = () => {
  return requestPro.get<any, provinceListType>(
    `/admin/cmn/dict/findByDictCode/province`
  );
};

//请求方法2:请求某个省份后的市  或者 请求某个市下边的区县
export const reqCityOrCounty = (parentId: string) => {
  return requestPro.get<any, provinceListType>(
    `/admin/cmn/dict/findByParentId/${parentId}`
  );
};
export const reqHosList = (params: hosListParamsType) => {
  const {
    page,
    limit,
    hoscode = "",
    hosname = "",
    hostype = "",
    provinceCode = "",
    cityCode = "",
    districtCode = "",
    status,
  } = params;
  //结构拿到的数据
  return requestHos.get<any, HosListDataType>(
    `/admin/hosp/hospital/${page}/${limit}`,
    {
      params: {
        hoscode,
        hosname,
        hostype,
        provinceCode,
        cityCode,
        districtCode,
        status,
      },
    }
  );
};
// 查看医院详情
export const reqHosDetail = (id: string) => {
  return requestHos.get<any, HosDetailType>(`/admin/hosp/hospital/show/${id}`);
};
//请求科室

export const reqSchedule = (hoscode: string) => {
  return requestHos.get<any, hosScheduleListType>(
    `/admin/hosp/department/${hoscode}`
  );
};

// 根据科室选择排班日期表
export const reqScheduleDate = (
  page: number,
  limit: number,
  hoscode: string,
  depcode: string
) => {
  return requestHos.get<any, hosScheduleDateType>(
    `/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`
  );
};

// 根据科室和日期请求医生列表
export const reqScheduleList = (
  hoscode: string,
  depcode: string,
  workDate: string
) => {
  return requestHos.get<any, scheduleListType>(
    `/admin/hosp/schedule/findScheduleList/${hoscode}/${depcode}/${workDate}`
  );
};

//更新医院上下线状态

export const reqHosStatus = (id: string, status: number) => {
  return requestHos.get<any, null>(
    `/admin/hosp/hospital/updateStatus/${id}/${status}`
  );
};
